home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Bin / DXUtils / Visual Studio 6.0 Wizards / DMToolWizard.awx / TEMPLATE / CLASSNAME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-11  |  25.5 KB  |  871 lines

  1. //------------------------------------------------------------------------------
  2. // File: $$CLASS_NAME$$.cpp
  3. //
  4. // Desc: DirectMusicTool Wizard generated code - Implementation of $$CLASS_NAME$$
  5. //
  6. // Author: $$TOOL_AUTHOR$$
  7. //
  8. // Copyright (c) Microsoft Corporation.  All rights reserved.
  9. //------------------------------------------------------------------------------
  10.  
  11.  
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif // _MSC_VER > 1000
  15.  
  16. #define STRICT
  17. #ifndef _WIN32_WINNT
  18. #define _WIN32_WINNT 0x0400
  19. #endif
  20.  
  21. #define _ATL_FREE_THREADED
  22. #define _ATL_STATIC_REGISTRY
  23.  
  24. #include <atlbase.h>
  25. //You may derive a class from CComModule and use it if you want to override
  26. //something, but do not change the name of _Module
  27. extern CComModule _Module;
  28. #include <atlcom.h>
  29. #include <atlctl.h>
  30. #include <statreg.h>
  31. #include <statreg.cpp>
  32. #include <atlimpl.cpp>
  33.  
  34.  
  35. #include "$$CLASS_NAME$$.h"
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // TODO List: 
  39. //  - Implement ProcessPMsg(), Init(), Flush()
  40. //  - Complete implementation for $$CLASS_NAME$$() and ~$$CLASS_NAME$$()
  41. //    if necessary
  42. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  43. //  - Complete implementation for SetAllParameters()
  44. //  - Complete implementation for GetAllParameters()
  45. //  - Complete implementation for SetParamInternal()
  46. $$ENDIF
  47. //  - Implement your custom memeber functions
  48. //
  49. /////////////////////////////////////////////////////////////////////////////
  50.  
  51. //
  52. // Interface Implementation
  53. //
  54.  
  55. //-----------------------------------------------------------------------------
  56. // Name: $$CLASS_NAME$$::$$CLASS_NAME$$()
  57. // Desc: Constructor
  58. //-----------------------------------------------------------------------------
  59. $$CLASS_NAME$$::$$CLASS_NAME$$()
  60. {
  61. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  62.     m_fDirty = TRUE;
  63. $$ENDIF
  64.     m_fInitialized = FALSE;
  65.  
  66. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  67.     // Initialize parameters in IMediaParam
  68.     InitParams(1, &GUID_TIME_REFERENCE, 0, 0, sizeof(g_params)/sizeof(*g_params), g_params);
  69. $$ENDIF
  70.  
  71. $$IF(EMPTY_TOOL)
  72. // TODO: Add initialization code here
  73.     m_dwParam1 = 0;    // m_dwParam1 is provided as an example
  74.  
  75. $$ELSE // Sample tool
  76.     m_dwEchoNum = 3;            // Default to 3 echoes per note
  77.     m_mtDelay = DMUS_PPQ / 2;   // Default to 8th note echoes
  78. $$ENDIF
  79. }
  80.  
  81. //-----------------------------------------------------------------------------
  82. // Name: $$CLASS_NAME$$::~$$CLASS_NAME$$()
  83. // Desc: Destructor
  84. //-----------------------------------------------------------------------------
  85. $$CLASS_NAME$$::~$$CLASS_NAME$$()
  86. {
  87.     // TODO: Add uninitialization code here
  88.     //
  89.  
  90. }
  91.  
  92. //-----------------------------------------------------------------------------
  93. // Name:    $$CLASS_NAME$$::Init()
  94. // Desc:    Initialize the tool
  95. //
  96. // Param:   pGraph - the Calling graph
  97. //
  98. // Return:  If succeeded, the method should return S_OK. If it fails, the return
  99. //            value might be E_POINTER or E_OUTOFMEMORY
  100. //
  101. // Remarks: This method is called when the tool is inserted into the graph,
  102. //            giving the tool an opportunity to perform any necessary
  103. //            initialization. Because a tool can be inserted into more than one
  104. //            graph, this method must be able to deal gracefully with multiple
  105. //            calls. Be sure not to create a circular reference to the graph
  106. //            represented by pGraph.
  107. //
  108. //            **This method is currently not implemeneted by the wizard**
  109. //
  110. //-----------------------------------------------------------------------------
  111. STDMETHODIMP $$CLASS_NAME$$::Init( IDirectMusicGraph* pGraph )
  112. {
  113.     HRESULT hr = S_OK;
  114.  
  115. // TODO: Do some initialization here if necessary
  116. //
  117.  
  118.     if(SUCCEEDED (hr))
  119.     {
  120.         m_fInitialized = TRUE;
  121.     }
  122.  
  123.     return S_OK;
  124. }
  125.  
  126. //-----------------------------------------------------------------------------
  127. // Name:    $$CLASS_NAME$$::Clone()
  128. // Desc:    Create a new instance of the tool
  129. //
  130. // Param:   ppTool - Address of a variable that receives a pointer to the
  131. //                      IDirectMusicTool interface of the new instnace of the
  132. //                     tool. Use QueryInterface to obtain IDirectMusicTool8.
  133. //
  134. // Return:  If succeeded, the method should return S_OK. If it fails, the return
  135. //            value might be E_POINTER, E_NOINTERFACE or E_OUTOFMEMORY
  136. //-----------------------------------------------------------------------------
  137. STDMETHODIMP $$CLASS_NAME$$::Clone( IDirectMusicTool ** ppTool)
  138. {
  139.     if( NULL == ppTool )    // Make sure pointer does not fail
  140.     {
  141.         return E_POINTER;
  142.     }
  143.  
  144.     $$CLASS_NAME$$ *pNew = new CComObject<$$CLASS_NAME$$>;
  145.     if (pNew)
  146.     {
  147.         HRESULT hr = pNew->QueryInterface( IID_IDirectMusicTool, (void **) ppTool );
  148.         if(SUCCEEDED(hr) && ppTool)
  149.         {
  150. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  151.             $$TOOLID_NAME$$Params params;
  152.             hr = this->GetAllParameters(¶ms);
  153.  
  154.             if(SUCCEEDED(hr))
  155.             {
  156.                 hr = pNew->SetAllParameters(¶ms);
  157.             }
  158.  
  159.             return hr;
  160. $$ELSE
  161.             return S_OK;
  162. $$ENDIF
  163.         }
  164.         else
  165.         {
  166.             return E_NOINTERFACE;
  167.         }
  168.     }
  169.     else
  170.     {
  171.         return E_OUTOFMEMORY;
  172.     }
  173. }
  174.  
  175. //-----------------------------------------------------------------------------
  176. // Name:    $$CLASS_NAME$$::GetMsgDeliveryType()
  177. // Desc:    Retrieve the tool's delivery type, which determines when messages are
  178. //            to be delivered to the tool
  179. //
  180. // Param:   pdwDeliveryType - Address of a variable that receives the delivery type
  181. //
  182. // Return:  If succeeded, the method should return S_OK. If it fails, the
  183. //            method can return E_POINTER
  184. //-----------------------------------------------------------------------------
  185. STDMETHODIMP $$CLASS_NAME$$::GetMsgDeliveryType( DWORD* pdwDeliveryType )
  186. {
  187.     if( NULL == pdwDeliveryType )    // Make sure pointer does not fail
  188.     {
  189.         return E_POINTER;
  190.     }
  191.  
  192. $$IF(DELIVERYTYPE_IMMEDIATE)
  193.     *pdwDeliveryType = DMUS_PMSGF_TOOL_IMMEDIATE;
  194. $$ELIF(DELIVERYTYPE_QUEUE)
  195.     *pdwDeliveryType = DMUS_PMSGF_TOOL_QUEUE;
  196. $$ELIF(DELIVERYTYPE_ATTIME)
  197.     *pdwDeliveryType = DMUS_PMSGF_TOOL_ATTIME;
  198. $$ELIF(!DELIVERYTYPE_IMMEDIATE && !DMUS_PMSGF_TOOL_QUEUE && !DMUS_PMSGF_TOOL_ATTIME)
  199.     // Set to default "DMUS_PMSGF_TOOL_IMMEDIATE"
  200.     *pdwDeliveryType = DMUS_PMSGF_TOOL_IMMEDIATE;
  201. $$ENDIF
  202.  
  203.     return S_OK;
  204. }
  205.  
  206. //-----------------------------------------------------------------------------
  207. // Name:    $$CLASS_NAME$$::GetMediaTypeArraySize()
  208. // Desc:    Retrieve the size of the array that must be passed into the
  209. //            IDirectMusicTool8::GetMediaTypes method
  210. //
  211. // Param:   pdwNumElements - Address of a variable that receives the number of
  212. //            media types
  213. //
  214. // Return:  If succeeded, the method should return S_OK. If it fails, the
  215. //            method can return E_POINTER
  216. //-----------------------------------------------------------------------------
  217. STDMETHODIMP $$CLASS_NAME$$::GetMediaTypeArraySize( DWORD* pdwNumElements )
  218. {
  219.     if( NULL == pdwNumElements )    // Make sure pointer does not fail
  220.     {
  221.         return E_POINTER;
  222.     }
  223.  
  224.     *pdwNumElements = $$TYPECOUNT$$;
  225.  
  226.     return S_OK;
  227. }
  228.  
  229. //-----------------------------------------------------------------------------
  230. // Name:    $$CLASS_NAME$$::GetMediaTypes()
  231. // Desc:    Get an array of the types processed by this tool
  232. //
  233. // Param:   padwMediaTypes - Address of an array of DWORDs. The method fills
  234. //                             this array with the media types supported by this tool
  235. //            dwNumElements  - Number of elements in the padwMediaTypes array.
  236. //                             This value is equal to the number returned by the
  237. //                             IDirectMusicTool8::GetMediaTypeArraySize method
  238. //
  239. // Return:  If succeeded, the method should return S_OK. If it fails, the return
  240. //            value might be E_POINTER or E_OUTOFMEMORY
  241. //-----------------------------------------------------------------------------
  242. STDMETHODIMP $$CLASS_NAME$$::GetMediaTypes( DWORD** padwMediaTypes, 
  243.                                             DWORD dwNumElements )
  244. {
  245.     if( NULL == padwMediaTypes )    // Make sure pointer does not fail
  246.     {
  247.         return E_POINTER;
  248.     }    
  249.     
  250.     // Fill in the array padwMediaTypes with the type of
  251.     // messages this tool wants to process if dwNumElements is equal to
  252.     // the returns from GetMediaTypeArraySize().
  253.  
  254.     if( dwNumElements == $$TYPECOUNT$$ )
  255.     {
  256. $$IF(TYPECOUNT_0)
  257.         (*padwMediaTypes)[0] = $$TYPE_0$$;
  258. $$ENDIF // TYPECOUNT_0
  259. $$IF(TYPECOUNT_1)
  260.         (*padwMediaTypes)[1] = $$TYPE_1$$;
  261. $$ENDIF // TYPECOUNT_1
  262. $$IF(TYPECOUNT_2)
  263.         (*padwMediaTypes)[2] = $$TYPE_2$$;
  264. $$ENDIF // TYPECOUNT_2
  265. $$IF(TYPECOUNT_3)
  266.         (*padwMediaTypes)[3] = $$TYPE_3$$;
  267. $$ENDIF // TYPECOUNT_3
  268. $$IF(TYPECOUNT_4)
  269.         (*padwMediaTypes)[4] = $$TYPE_4$$;
  270. $$ENDIF // TYPECOUNT_4
  271. $$IF(TYPECOUNT_5)
  272.         (*padwMediaTypes)[5] = $$TYPE_5$$;
  273. $$ENDIF // TYPECOUNT_5
  274. $$IF(TYPECOUNT_6)
  275.         (*padwMediaTypes)[6] = $$TYPE_6$$;
  276. $$ENDIF // TYPECOUNT_6
  277. $$IF(TYPECOUNT_7)
  278.         (*padwMediaTypes)[7] = $$TYPE_7$$;
  279. $$ENDIF // TYPECOUNT_7
  280. $$IF(TYPECOUNT_8)
  281.         (*padwMediaTypes)[8] = $$TYPE_8$$;
  282. $$ENDIF // TYPECOUNT_8
  283. $$IF(TYPECOUNT_9)
  284.         (*padwMediaTypes)[9] = $$TYPE_9$$;
  285. $$ENDIF // TYPECOUNT_9
  286. $$IF(TYPECOUNT_10)
  287.         (*padwMediaTypes)[10] = $$TYPE_10$$;
  288. $$ENDIF // TYPECOUNT_10
  289. $$IF(TYPECOUNT_11)
  290.         (*padwMediaTypes)[11] = $$TYPE_11$$;
  291. $$ENDIF // TYPECOUNT_11
  292. $$IF(TYPECOUNT_12)
  293.         (*padwMediaTypes)[12] = $$TYPE_12$$;
  294. $$ENDIF // TYPECOUNT_12
  295. $$IF(TYPECOUNT_13)
  296.         (*padwMediaTypes)[13] = $$TYPE_13$$;
  297. $$ENDIF // TYPECOUNT_13
  298. $$IF(TYPECOUNT_14)
  299.         (*padwMediaTypes)[14] = $$TYPE_14$$;
  300. $$ENDIF // TYPECOUNT_14
  301. $$IF(TYPECOUNT_15)
  302.         (*padwMediaTypes)[15] = $$TYPE_15$$;
  303. $$ENDIF // TYPECOUNT_15
  304.         return S_OK;
  305.     }
  306.     else
  307.     {
  308.         // This should never happen
  309.         return E_FAIL;
  310.     }
  311. }
  312.  
  313. //-----------------------------------------------------------------------------
  314. // Name:    $$CLASS_NAME$$::ProcessPMsg()
  315. // Desc:    Perform the main task of the tool -- process PMsg
  316. //
  317. // Param:   pPerf  - Performance that is generating messages
  318. //            pPMsg  - Message to process
  319. //
  320. // Return:  If succeeded, the method should return one of DMUS_S_REQUEUE,
  321. //            DMUS_S_FREE, or S_OK. If it fails, the method can return E_POINTER
  322. //
  323. //-----------------------------------------------------------------------------
  324. STDMETHODIMP $$CLASS_NAME$$::ProcessPMsg( IDirectMusicPerformance* pPerf, 
  325.                                           DMUS_PMSG* pPMsg )
  326. {
  327.     if( NULL == pPerf || NULL == pPMsg )    // Make sure pointers do not fail
  328.     {
  329.         return E_POINTER;
  330.     }
  331.  
  332.     // Save the current PChannel, since calling StampPMsg may change it.
  333. // TODO: Uncomment the following line if you need to remember the PChannel
  334.     //DWORD dwPChannel = pPMsg->dwPChannel;
  335.  
  336.     // Stamp the message to be delivered to the next tool in the graph.
  337.     // If StampPMsg fails, there is no destination for this message, so
  338.     // tell the performance to free it.
  339.     if(( NULL == pPMsg->pGraph ) ||
  340.         FAILED(pPMsg->pGraph->StampPMsg(pPMsg)))
  341.     {
  342.         return DMUS_S_FREE;
  343.     }
  344.  
  345. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  346.     // Update parameter values from any curves that may be in effect.
  347.     // We pick up the current values stored in the CParamsManager helper for time rtStart. 
  348.     this->UpdateActiveParams(pPMsg->rtTime, *this);
  349. $$ENDIF
  350.  
  351. $$IF(EMPTY_TOOL)
  352.  
  353.     // TODO: Add your custom code here
  354.  
  355.     // Process each message type
  356.     switch(pPMsg->dwType)
  357.     {
  358. $$IF(PROCESS_MIDI)
  359.         case DMUS_PMSGT_MIDI:
  360.         // TODO: Add your process code for PMsg type DMUS_PMSGT_MIDI
  361.  
  362.             break;
  363. $$ENDIF
  364. $$IF(PROCESS_NOTE)
  365.         case DMUS_PMSGT_NOTE:
  366.         // TODO: Add your process code for PMsg type DMUS_PMSGT_NOTE
  367.  
  368.             break;
  369. $$ENDIF
  370. $$IF(PROCESS_SYSEX)
  371.         case DMUS_PMSGT_SYSEX:
  372.         // TODO: Add your process code for PMsg type DMUS_PMSGT_SYSEX
  373.  
  374.             break;
  375. $$ENDIF
  376. $$IF(PROCESS_NOTIFICATION)
  377.         case DMUS_PMSGT_NOTIFICATION:
  378.         // TODO: Add your process code for PMsg type DMUS_PMSGT_NOTIFICATION
  379.  
  380.             break;
  381. $$ENDIF
  382. $$IF(PROCESS_TEMPO)
  383.         case DMUS_PMSGT_TEMPO:
  384.         // TODO: Add your process code for PMsg type DMUS_PMSGT_TEMPO
  385.  
  386.             break;
  387. $$ENDIF
  388. $$IF(PROCESS_CURVE)
  389.         case DMUS_PMSGT_CURVE:
  390.         // TODO: Add your process code for PMsg type DMUS_PMSGT_CURVE
  391.  
  392.             break;
  393. $$ENDIF
  394. $$IF(PROCESS_TIMESIG)
  395.         case DMUS_PMSGT_TIMESIG:
  396.         // TODO: Add your process code for PMsg type DMUS_PMSGT_TIMESIG
  397.  
  398.             break;
  399. $$ENDIF
  400. $$IF(PROCESS_PATCH)
  401.         case DMUS_PMSGT_PATCH:
  402.         // TODO: Add your process code for PMsg type DMUS_PMSGT_PATCH
  403.  
  404.             break;
  405. $$ENDIF
  406. $$IF(PROCESS_TRANSPOSE)
  407.         case DMUS_PMSGT_TRANSPOSE:
  408.         // TODO: Add your process code for PMsg type DMUS_PMSGT_TRANSPOSE
  409.  
  410.             break;
  411. $$ENDIF
  412. $$IF(PROCESS_CHANNEL_PRIORITY)
  413.         case DMUS_PMSGT_CHANNEL_PRIORITY:
  414.         // TODO: Add your process code for PMsg type DMUS_PMSGT_CHANNEL_PRIORITY
  415.  
  416.             break;
  417. $$ENDIF
  418. $$IF(PROCESS_STOP)
  419.         case DMUS_PMSGT_STOP:
  420.         // TODO: Add your process code for PMsg type DMUS_PMSGT_STOP
  421.  
  422.             break;
  423. $$ENDIF
  424. $$IF(PROCESS_DIRTY)
  425.         case DMUS_PMSGT_DIRTY:
  426.         // TODO: Add your process code for PMsg type DMUS_PMSGT_DIRTY
  427.  
  428.             break;
  429. $$ENDIF
  430. $$IF(PROCESS_WAVE)
  431.         case DMUS_PMSGT_WAVE:
  432.         // TODO: Add your process code for PMsg type DMUS_PMSGT_WAVE
  433.  
  434.             break;
  435. $$ENDIF
  436. $$IF(PROCESS_LYRIC)
  437.         case DMUS_PMSGT_LYRIC:
  438.         // TODO: Add your process code for PMsg type DMUS_PMSGT_LYRIC
  439.  
  440.             break;
  441. $$ENDIF
  442. $$IF(PROCESS_SCRIPTLYRIC)
  443.         case DMUS_PMSGT_SCRIPTLYRIC:
  444.         // TODO: Add your process code for PMsg type DMUS_PMSGT_SCRIPTLYRIC
  445.  
  446.             break;
  447. $$ENDIF
  448. $$IF(PROCESS_USER)
  449.         case DMUS_PMSGT_USER:
  450.         // TODO: Add your process code for PMsg type DMUS_PMSGT_USER
  451.  
  452.             break;
  453. $$ENDIF
  454.         default: { /* TODO: Do something for default if necessary */ }
  455.     }
  456.  
  457.     // TODO: Remeber to deallocate local variables that are no longer needed
  458.  
  459.  
  460. $$IF(POSTPROC_REQUEUE)
  461.     return DMUS_S_REQUEUE;    // Requeue message
  462. $$ELIF(POSTPROC_FREE)
  463.     return DMUS_S_FREE;        // Free message automatically (PMsg no longer needed)
  464. $$ELIF(POSTPROC_S_OK)
  465.     return S_OK;
  466. $$ELIF(!DELIVERYTYPE_IMMEDIATE && !DMUS_PMSGF_TOOL_QUEUE && !DMUS_PMSGF_TOOL_ATTIME)
  467.     // Set to default "DMUS_S_REQUEUE"
  468.     return DMUS_S_REQUEUE;    // Requeue message
  469. $$ENDIF
  470.  
  471. $$ELSE    // Sample Tool
  472.  
  473.     DWORD dwCount;
  474.     DWORD dwEchoNum;
  475.     MUSIC_TIME mtDelay;
  476.     
  477.     // SetEchoNum() and SetDelay() use these member variables,
  478.     dwEchoNum = m_dwEchoNum;
  479.     mtDelay = m_mtDelay;
  480.  
  481.     // The Tool is set up to only receive messages of types
  482.     // DMUS_PMSGT_NOTE, DMUS_PMSGT_MIDI, DMUS_PMSGT_SYSEX, or DMUS_PMSGT_PATCH
  483.     // We use the DX8 ClonePMsg method to make a copy of the pmsg and
  484.     // send it to a pchannel in the next pchannel group. 
  485.     // If it's a note, we also doctor the velocity.
  486.     IDirectMusicPerformance8 *pPerf8;
  487.     if (SUCCEEDED(pPerf->QueryInterface(IID_IDirectMusicPerformance8,(void **)&pPerf8)))
  488.     {
  489.         for( dwCount = 1; dwCount <= dwEchoNum; dwCount++ )
  490.         {
  491.             DMUS_PMSG *pClone;
  492.             if( SUCCEEDED( pPerf8->ClonePMsg( pPMsg,&pClone)))
  493.             {
  494.                 // Add to the time of the echoed note
  495.                 pClone->mtTime += (dwCount * mtDelay);
  496.                 if (pPMsg->dwType == DMUS_PMSGT_NOTE )
  497.                 {
  498.                     DMUS_NOTE_PMSG *pNote = (DMUS_NOTE_PMSG*)pPMsg;
  499.                     DMUS_NOTE_PMSG *pCloneNote = (DMUS_NOTE_PMSG*)pClone;
  500.                     // Reduce the volume of the echoed note
  501.                     // percentage of reduction in velocity increases with each echo
  502.                     pCloneNote->bVelocity = (BYTE) (pNote->bVelocity - 
  503.                         ((pNote->bVelocity * (dwCount * 15)) / 100));
  504.                 }
  505.                 // Set the note so only MUSIC_TIME is valid.
  506.                 // REFERENCE_TIME will be recomputed inside
  507.                 // SendPMsg()
  508.                 pClone->dwFlags = DMUS_PMSGF_MUSICTIME;
  509.                 pClone->dwPChannel = pPMsg->dwPChannel + (16 * dwCount);
  510.                 // Queue the echoed PMsg
  511.                 pPerf->SendPMsg(pClone);
  512.             }
  513.         }
  514.         pPerf8->Release();
  515.     }
  516.  
  517.     // Return DMUS_S_REQUEUE so the original message is requeued
  518.     return DMUS_S_REQUEUE;
  519. $$ENDIF
  520. }
  521.  
  522. //-----------------------------------------------------------------------------
  523. // Name:    $$CLASS_NAME$$::Flush()
  524. // Desc:    Flushes messages from the queue when the performance stops
  525. //
  526. // Param:   pPerf       - Address of the IDirectMusicPerformance8 interface
  527. //            pDMUS_PMSG  - Message to flush
  528. //            rt          - Time at which to flush
  529. //
  530. // Return:  If succeeded, the method should return one of DMUS_S_REQUEUE,
  531. //            DMUS_S_FREE, or S_OK. If it fails, the method can return E_POINTER
  532. //
  533. //
  534. // Remarks: The tool can use the method to do whatever is necessary to flush
  535. //            the message. For instance, the output tool uses this method to
  536. //            ensure that any pending note-off messages are processed immediately
  537. //
  538. //            **This method is currently not implemeneted by the wizard**
  539. //
  540. //-----------------------------------------------------------------------------
  541. STDMETHODIMP $$CLASS_NAME$$::Flush( IDirectMusicPerformance* pPerf, 
  542.                                     DMUS_PMSG* pDMUS_PMSG,
  543.                                     REFERENCE_TIME rt)
  544. {
  545.     // TODO: To implement, replace the following line with your code
  546.     //
  547.     return DMUS_S_REQUEUE;
  548. }
  549.  
  550. $$IF(!EMPTY_TOOL) // Sample Tool
  551. //-----------------------------------------------------------------------------
  552. // Name: $$CLASS_NAME$$::SetEchoNum()
  553. // Desc: Set the number of echoes. Upperbound set by MAX_ECHOES
  554. //-----------------------------------------------------------------------------
  555. STDMETHODIMP_(void) $$CLASS_NAME$$::SetEchoNum( DWORD dwEchoNum )
  556. {
  557.     if( dwEchoNum <= MAX_ECHOES )
  558.     {
  559.         m_dwEchoNum = dwEchoNum;
  560.     }
  561. }
  562.  
  563. //-----------------------------------------------------------------------------
  564. // Name: $$CLASS_NAME$$::SetDelay()
  565. // Desc: Set the length of delay for each echo
  566. //-----------------------------------------------------------------------------
  567. STDMETHODIMP_(void) $$CLASS_NAME$$::SetDelay( MUSIC_TIME mtDelay )
  568. {
  569.     m_mtDelay = mtDelay;
  570. }
  571. $$ENDIF // End => Sample tool
  572.  
  573.  
  574. $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  575. //-----------------------------------------------------------------------------
  576. // Name: $$CLASS_NAME$$::SetParamInternal()
  577. // Desc: Set the indicated parameter
  578. //-----------------------------------------------------------------------------
  579. HRESULT $$CLASS_NAME$$::SetParamInternal(DWORD dwParamIndex, MP_DATA value, bool fSkipPasssingToParamManager)
  580. {
  581.     switch (dwParamIndex)
  582.     {
  583. $$IF(EMPTY_TOOL)
  584.     case $$TOOL_DEFINE$$_PARAM1:
  585.         m_dwParam1 = (DWORD)value;    // m_dwParam1 is provided as an example
  586.         break;
  587.     // TODO: Add cases for each of your parameters
  588. $$ELSE    // Sample DMTool
  589.     case ECHO_NUMBER:
  590.         m_dwEchoNum = (DWORD)value;
  591.         break;
  592.     case ECHO_DELAY:
  593.         m_mtDelay = (MUSIC_TIME)value;
  594.         break;
  595. $$ENDIF // End EMPTY_TOOL
  596.     }
  597.  
  598.     // Let base class set this so it can handle all the rest of the param calls.
  599.     // Skip the base class if fSkipPasssingToParamManager.  This indicates that we're calling the function
  600.     //    internally using values that came from the base class -- thus there's no need to tell it values it
  601.     //    already knows.
  602.     return fSkipPasssingToParamManager ? S_OK : CParamsManager::SetParam(dwParamIndex, value);
  603. }
  604.  
  605. //////////////////
  606. //  Macros used by GetAllParameters() and SetAllParameters()
  607. //
  608. // GET_PARAM_DWORD()
  609. #define GET_PARAM_DWORD(x, y) \
  610.     if (SUCCEEDED(hr)) \
  611.     { \
  612.         hr = GetParam(x, &var); \
  613.         if (SUCCEEDED(hr)) \
  614.         { \
  615.             y = (DWORD)var; \
  616.         } \
  617.     }
  618.  
  619. // GET_PARAM_FLOAT()
  620. #define GET_PARAM_FLOAT(x, y) \
  621.     if (SUCCEEDED(hr)) \
  622.     { \
  623.         hr = GetParam(x, &var); \
  624.         if (SUCCEEDED(hr)) \
  625.         { \
  626.             y = (float)var; \
  627.         } \
  628.     }
  629.  
  630. // SET_PARAM()
  631. #define SET_PARAM(x, y) \
  632.     if (SUCCEEDED(hr)) \
  633.     { \
  634.         hr = SetParam(x, static_cast<MP_DATA>(y)); \
  635.     }
  636.  
  637. //-----------------------------------------------------------------------------
  638. // Name: $$CLASS_NAME$$::SetAllParameters()
  639. // Desc: Set all parameters
  640. //-----------------------------------------------------------------------------
  641. STDMETHODIMP $$CLASS_NAME$$::SetAllParameters(THIS_ LPC$$TOOLID_NAME$$Params pParm)
  642. {
  643.     HRESULT hr = S_OK;
  644.  
  645.     // Check that the pointer is not NULL
  646.     if (pParm == NULL)
  647.     {
  648.         hr = E_POINTER;
  649.     }
  650.  
  651.     // Set the parameters
  652.     if (SUCCEEDED(hr))
  653.     {
  654. $$IF(EMPTY_TOOL)
  655.     // TODO: Set all parameters with values stored in pParm. Example:
  656.         SET_PARAM($$TOOL_DEFINE$$_PARAM1, pParm->dwParam1);
  657.     // End of Example
  658. $$ELSE    // Sample DMTool
  659.         SET_PARAM(ECHO_NUMBER,  pParm->dwNumber);
  660.         SET_PARAM(ECHO_DELAY, pParm->dwDelay);
  661. $$ENDIF // End EMPTY_TOOL
  662.     }
  663.  
  664.     m_fDirty = TRUE;
  665.     return hr;
  666. }
  667.  
  668. //-----------------------------------------------------------------------------
  669. // Name: $$CLASS_NAME$$::GetAllParameters()
  670. // Desc: Set all parameters
  671. //-----------------------------------------------------------------------------
  672. STDMETHODIMP $$CLASS_NAME$$::GetAllParameters(THIS_ LP$$TOOLID_NAME$$Params pParm)
  673. {
  674.     HRESULT hr    = S_OK;
  675.     MP_DATA var;
  676.  
  677.     if (pParm == NULL)
  678.     {
  679.         return E_POINTER;
  680.     }
  681.  
  682. $$IF(EMPTY_TOOL)
  683. // TODO: Get all parameter values into pParm.
  684.     // Example:
  685.     GET_PARAM_DWORD($$TOOL_DEFINE$$_PARAM1, pParm->dwParam1);
  686.     // End of Example
  687. $$ELSE    // Sample DMTool
  688.      GET_PARAM_DWORD(ECHO_NUMBER, pParm->dwNumber);
  689.     GET_PARAM_DWORD(ECHO_DELAY, pParm->dwDelay);
  690. $$ENDIF // End EMPTY_TOOL
  691.  
  692.     return hr;
  693. }
  694.  
  695. //-----------------------------------------------------------------------------
  696. // Name: $$CLASS_NAME$$::GetClassID()
  697. // Desc: Get the class ID for this class
  698. //-----------------------------------------------------------------------------
  699. HRESULT $$CLASS_NAME$$::GetClassID(CLSID *pClsid)
  700. {
  701.     // Check for valid pointer
  702.     if( NULL == pClsid )
  703.     {
  704.         return E_POINTER;
  705.     }
  706.  
  707.     *pClsid = CLSID_$$TOOL_DEFINE$$;
  708.     return S_OK;
  709.  
  710. } // GetClassID
  711.  
  712.  
  713. //-----------------------------------------------------------------------------
  714. // Name: $$CLASS_NAME$$::IsDirty()
  715. // Desc: Checks the object for changes since it was last saved
  716. //-----------------------------------------------------------------------------
  717. HRESULT $$CLASS_NAME$$::IsDirty()
  718. {
  719.     return m_fDirty ? S_OK : S_FALSE;
  720. }
  721.  
  722. //-----------------------------------------------------------------------------
  723. // Name: $$CLASS_NAME$$::Load()
  724. // Desc: Initializes an object from the stream where it was previously saved
  725. //-----------------------------------------------------------------------------
  726. HRESULT $$CLASS_NAME$$::Load(IStream *pStm) 
  727.     ULONG ulSizeRead = 0;
  728.     HRESULT hr = S_OK;
  729.  
  730.     if ( pStm == NULL )
  731.     {
  732.         return E_POINTER;
  733.     }
  734.  
  735.     $$TOOLID_NAME$$Params params;
  736. $$IF(SUPPORT_DM_DMP)
  737.  
  738.     // Since DirectMusic expects the data to be in RIFF format, we'll read
  739.     // the input as a valid RIFF chunk
  740.     DWORD dwChunkID;
  741.     DWORD dwSize;
  742.  
  743.     // Read RIFF form type chunk
  744.     hr = pStm->Read((void *)&dwChunkID, sizeof(dwChunkID), &ulSizeRead);
  745.     if (FAILED(hr) || dwChunkID != FOURCC_TOOL_CHUNK)    // If Read() failed or invalid chunk type
  746.     {
  747.         return hr;
  748.     }
  749.  
  750.     // Read RIFF size chunk
  751.     hr = pStm->Read((void *)&dwSize, sizeof(dwSize), &ulSizeRead);
  752.     if (FAILED(hr) || dwSize != sizeof($$TOOLID_NAME$$Params))    // If Read() failed or invalid chunk size
  753.     {
  754.         return hr;
  755.     }
  756. $$ENDIF // End SUPPORT_DM_DMP
  757.  
  758.     // Read the parameters
  759.     hr = pStm->Read((void *)¶ms, sizeof(params), &ulSizeRead);
  760.     if (hr != S_OK || ulSizeRead < sizeof(params))
  761.     {
  762.         return E_FAIL;
  763.     }
  764.  
  765.     hr = SetAllParameters(¶ms);
  766.  
  767.     m_fDirty = FALSE;
  768.  
  769.     return hr;
  770. }
  771.  
  772. //-----------------------------------------------------------------------------
  773. // Name: $$CLASS_NAME$$::Save()
  774. // Desc: This method saves an object to the specified stream
  775. //-----------------------------------------------------------------------------
  776. HRESULT $$CLASS_NAME$$::Save(IStream *pStm, BOOL fClearDirty) 
  777. {
  778.     HRESULT hr = S_OK; 
  779.  
  780.     if ( pStm == NULL )
  781.     {
  782.         return E_POINTER;
  783.     }
  784.  
  785.     $$TOOLID_NAME$$Params params;
  786.     hr = GetAllParameters(¶ms);
  787.     if (FAILED(hr))
  788.     {
  789.         return hr;
  790.     }
  791.  
  792.     ULONG ulSizeWritten = 0;
  793. $$IF(SUPPORT_DM_DMP)
  794.  
  795.     // Since DirectMusic expects the data to be in RIFF format, we'll make
  796.     // the output to pStm a valid RIFF chunk
  797.     DWORD dwChunkID = FOURCC_TOOL_CHUNK;
  798.     DWORD dwSize = sizeof($$TOOLID_NAME$$Params);
  799.  
  800.     // Write RIFF form type chunk
  801.     hr = pStm->Write((void *)&dwChunkID, sizeof(dwChunkID), &ulSizeWritten);
  802.     if (FAILED(hr))
  803.     {
  804.         return hr;
  805.     }
  806.  
  807.     // Write RIFF size chunk
  808.     hr = pStm->Write((void *)&dwSize, sizeof(dwSize), &ulSizeWritten);
  809.     if (FAILED(hr))
  810.     {
  811.         return hr;
  812.     }
  813. $$ENDIF // End SUPPORT_DM_DMP
  814.  
  815.     // Write the parameters
  816.     hr = pStm->Write((void *)¶ms, sizeof(params), &ulSizeWritten);
  817.  
  818.     if (hr != S_OK || ulSizeWritten < sizeof(params))
  819.     {
  820.         return E_FAIL;
  821.     }
  822.  
  823.     if (fClearDirty)
  824.     {
  825.         m_fDirty = FALSE;
  826.     }
  827.  
  828.     return S_OK;
  829. }
  830.  
  831. //-----------------------------------------------------------------------------
  832. // Name: $$CLASS_NAME$$::GetSizeMax()
  833. // Desc: This method returns the size in bytes of the stream needed to save the object
  834. //-----------------------------------------------------------------------------
  835. HRESULT $$CLASS_NAME$$::GetSizeMax(ULARGE_INTEGER *pcbSize) 
  836.     if ( NULL == pcbSize )
  837.         return E_POINTER; 
  838.  
  839.     // Total size = size of(parameters) + sizeof(RIFF form type chunk) + sizeof(size chunk)
  840.     pcbSize->QuadPart = sizeof($$TOOLID_NAME$$Params) + 2 * sizeof(DWORD); 
  841.     return S_OK; 
  842. }
  843. $$ENDIF // END (SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
  844.  
  845. $$IF(SUPPORT_DM_DMP)
  846. //-----------------------------------------------------------------------------
  847. // Name: $$CLASS_NAME$$::GetPages()
  848. // Desc: Get the property pages GUIDs
  849. //-----------------------------------------------------------------------------
  850. HRESULT $$CLASS_NAME$$::GetPages(CAUUID *pPages)
  851. {
  852.     // Only one property page is required for DMTool
  853.     pPages->cElems = 1;
  854.     pPages->pElems = static_cast<GUID *>(CoTaskMemAlloc(sizeof(GUID)));
  855.  
  856.     // Make sure memory is allocated for pPages->pElems
  857.     if( pPages->pElems == NULL )
  858.     {
  859.         return E_OUTOFMEMORY;
  860.     }
  861.  
  862.     // Return the propery page's class ID
  863.     *(pPages->pElems) = CLSID_$$TOOL_DEFINE$$PROP;
  864.     return S_OK;
  865. }
  866.  
  867. $$ENDIF // END SUPPORT_DM_DMP
  868.  
  869.